#ifndef _DEC_AUDIO_RAW_H_
#define _DEC_AUDIO_RAW_H_

extern "C" {
#include <libavutil/frame.h>
#include <libavutil/mem.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
}

#include <string>
#include <map>

#define AUDIO_INBUF_SIZE 20480

class FmtCvt;
class AudioDecodeRaw
{
public:
    AudioDecodeRaw();
    ~AudioDecodeRaw();

    int init(enum AVCodecID id = AV_CODEC_ID_MP3);
    int init(const std::string& id);
    //int init(const std::string& id = "MP3");
    int destroy();
    int decode(const uint8_t* data, int data_size, uint8_t** out_pptr);

private:
    bool _decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame);
    int _init();

private:
    AVCodec* m_codec;
    AVCodecContext* m_codec_ctx;
    AVCodecParserContext* m_parser_ctx;
    AVPacket* m_pkt;
    AVFrame* m_frm;
    FmtCvt* m_swr;
    uint8_t* m_buffer;
    int m_buffer_size;
    int m_buffer_capacity;
    //std::map<const std::string, AVCodecID> m_codec_map;
};

#endif
